package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.project.biz.admin.service.IBizUserIdentityAuditRecordService;
import cn.sfrog.system.domain.vo.biz.BizMemberQueryVO;
import cn.sfrog.system.domain.vo.biz.BizMemberResultVO;
import cn.sfrog.system.domain.vo.biz.BizUpdateStatusVO;
import cn.sfrog.system.domain.vo.biz.BizUserAuditVO;
import cn.sfrog.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "管理后台-会员相关")
@RestController
@RequestMapping("/biz/member")
public class BizMemberController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IBizUserIdentityAuditRecordService bizUserIdentityAuditRecordService;

    /**
     * 查询会员列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizMemberQueryVO queryVO) {
        startPage();
        List<BizMemberResultVO> list = sysUserService.selectMemberUserList(queryVO);
        return getDataTable(list);
    }

    /**
     * 获取医院详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:member:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        BizMemberResultVO resultVO = sysUserService.selectMemberUserById(userId);
        return AjaxResult.success(resultVO);
    }

    /**
     * 禁用启用
     * @return
     */
    @ApiOperation("禁用启用")
    @PreAuthorize("@ss.hasPermi('biz:member:changeStatus')")
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@Validated @RequestBody BizUpdateStatusVO vo) {
       Integer index = sysUserService.changeStatus(vo);
       return AjaxResult.success(index);
    }

    /**
     * 身份审核
     * @return
     */
    @ApiOperation("身份审核")
    @PreAuthorize("@ss.hasPermi('biz:member:audit')")
    @PostMapping("/audit")
    public AjaxResult audit(@Validated @RequestBody BizUserAuditVO vo) {
        return AjaxResult.success(bizUserIdentityAuditRecordService.audit(vo));
    }
}
